package ext.mango.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Iterator;
import java.util.Properties;

public class Properties2Xml {
    public static void main(String[] args) throws IOException {
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("ext/mango/utils/messages.properties");
        Properties p = new Properties();
        p.load(in);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("D:/messages.xml"))));
        bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        bw.write("<messages>\n");
        Iterator<Object> iter = p.keySet().iterator();
        while(iter.hasNext()) {
            String key = (String) iter.next();
            String value = p.getProperty(key);
            System.out.println(key + ":" + value);
            bw.write("    ");
            bw.write("<string id=\"");
            bw.write(key);
            bw.write("\">");
            bw.write(value);
            bw.write("</string>\n");
        }
        bw.write("</messages>\n");
        bw.flush();
        bw.close();
    }
}
